package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Sign;
import cn.wolfcode.trip.base.mapper.SignMapper;
import cn.wolfcode.trip.base.service.ISignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class SignServiceImpl implements ISignService{
    @Autowired
    private SignMapper signMapper;

    public List<Sign> selectAllDays(Long userId) {
        return signMapper.selectAllDays(userId);
    }

    public void save(Sign sign) {
        sign.setSignTime(new Date());
        sign.setState(0);
        signMapper.save(sign);
    }

    public Integer SelectSignState() {
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = dateFormat.format(date);
        try {
            Date date1 = dateFormat.parse(format);
            int i = signMapper.selectState(date1);
            return i;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return -1;
    }
}
